﻿Imports System.IO

Public Class get_Help

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="HelpFileName">HelpFile = "Setup_Infos.rtf"</param>
    ''' <remarks></remarks>
    Sub New(HelpFileName As String)
        If HelpfileName.Length > 0 Then
            Main_Help(GetAppPath() & "\" & HelpfileName)
        Else
            MessageBox.Show("HelpFile not found!", "Error: <get_Help>", MessageBoxButtons.OK)
        End If
    End Sub


    Private Sub Main_Help(FullHelpFileName As String)
        Try
            If My.Computer.FileSystem.FileExists(FullHelpFileName) Then

                Start_with_linked_Application(FullHelpFileName)
            Else
                If is_Language_German_Active() Then
                    MessageBox.Show(FullHelpFileName, "Hilfe-Datei nicht gefunden!", MessageBoxButtons.OK)
                Else
                    MessageBox.Show(FullHelpFileName, "Help-File not found!", MessageBoxButtons.OK)
                End If
            End If
            Exit Sub
        Catch ex As Exception
            Exit Sub
        End Try
    End Sub

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function GetAppPath() As String
        Try
            Return Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly.Location())
        Catch ex As Exception
            Return String.Empty
        End Try
    End Function


    ''' <summary>
    ''' open created File with linked Application
    ''' </summary>
    ''' <param name="FileName"></param>
    ''' <remarks>
    ''' open TXT-File with Editor 
    ''' open HTML-File with Internet Explorer or FireFox 
    ''' open XLS-File with Excel or OpenOffice
    ''' </remarks>
    Private Sub Start_with_linked_Application(FileName As String)
        Try
            If File.Exists(FileName) Then

                Dim pInfo As New ProcessStartInfo()
                pInfo.FileName = FileName
                pInfo.UseShellExecute = True
                Dim p As Process = Process.Start(pInfo)

            Else
                If is_Language_German_Active() Then
                    MessageBox.Show(FileName, "Fehler: Datei kann nicht geöffnet werden!", MessageBoxButtons.OK)
                Else
                    MessageBox.Show(FileName, "Error: File can not exclusive opend!", MessageBoxButtons.OK)
                End If
            End If
            Exit Sub
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Error: Start_with_Application", MessageBoxButtons.OK)
            Exit Sub
        End Try
    End Sub

    ''' <summary>
    ''' determine if in Windows as a language German active 
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function is_Language_German_Active() As Boolean
        Try
            Dim cultureName As String = Threading.Thread.CurrentThread.CurrentCulture.Name
            If cultureName.Substring(0, 2) = "de" Then
                is_Language_German_Active = True
            Else
                is_Language_German_Active = False
            End If
        Catch
            is_Language_German_Active = False
        End Try
    End Function

End Class
